package exam.dfs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.Arrays;

/**
 * 修复幻方
 * 找出交换了位置的两个数字, 输出行数列数和对应的数字
 * 输入 3
 *      8 1 9
 *      3 5 7
 *      4 6 2
 * 输出 1 3 6
 *      3 2 9
 *
 * @author shenenlu 2021年06月04日 下午14:02:37
 */
public class RepairMagicSquare {

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        //n代表阶数
        int n = Integer.parseInt(bufferedReader.readLine());
        int[] arr = new int[n*n];
        for(int i=0; i<n ;i++){
            int arrIndex = i * n;
            String[] strArr = bufferedReader.readLine().split(" ");
            for(String str : strArr){
                int val = Integer.parseInt(str);
                arr[arrIndex++] = val;
            }
        }

        RepairMagicSquare repairMagicSquare = new RepairMagicSquare();
        repairMagicSquare.dfs(0, arr, n);
        System.out.println( repairMagicSquare.index1+","+repairMagicSquare.index2);
    }


    int index1;
    int index2;

    void dfs(int index, int[] arr, int n){
        if( index >= arr.length){
            return;
        }
        if( checkArr(arr, n)){
            return;
        }

        for(int i=index + 1; i< arr.length; i++){
            if( tryRepair(arr, n, index, i) ){
                index1 = index;
                index2 = i;
                return;
            }
        }
        dfs(index + 1, arr, n);
    }

    private boolean tryRepair(int[] arr, int n, int index1, int index2) {
        int[] newArr = Arrays.copyOf(arr, arr.length);
        int temp = newArr[index1];
        newArr[index1] = newArr[index2];
        newArr[index2] = temp;
        return checkArr(newArr, n);
    }

    private boolean checkArr(int[] arr, int n) {
        int lineSum = getLineSum(0, arr, n);
        int lineIndex = 1;
        while ( lineIndex < n ){
            if( lineSum != getLineSum(lineIndex++, arr, n)){
                return false;
            }
        }
        int verticalIndex = 0;
        while ( verticalIndex < n ){
            if( lineSum != getVerticalSum(verticalIndex++, arr, n)){
                return false;
            }
        }
        if( lineSum != getSlantedSumLeftToRight(arr, n) ){
            return false;
        }
        return lineSum == getSlantedSumRightToLeft(arr, n);
    }

    int getLineSum(int lineIndex, int[] arr, int n ){
        int lineSum = 0;
        for(int i=lineIndex*n; i<lineIndex*n + n; i++){
            lineSum += arr[i];
        }
        return lineSum;
    }

    int getVerticalSum(int verticalIndex, int[] arr, int n ){
        int verticalIndexSum = 0;
        for(int i=0; i< n; i++){
            verticalIndexSum += arr[i * n + verticalIndex];
        }
        return verticalIndexSum;
    }

    int getSlantedSumLeftToRight(int[] arr, int n ){
        int index = 0;
        int sum = 0;
        while (index < n*n){
            sum += arr[index];
            index += n+1;
        }
        return sum;
    }

    int getSlantedSumRightToLeft(int[] arr, int n ){
        int sum = 0;
        for(int i=0; i<n; i++){
            sum += arr[i*n+(n-1)];
        }
        return sum;
    }

}
